<template>
  <div>
    <el-table
      ref="multipleTable"
      :data="tableData"
      stripe
      row-key="id"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="55"
        reserve-selection
      ></el-table-column>
      <el-table-column prop="title" label="文章标题" show-overflow-tooltip>
        <template slot-scope="{ row }">
          <span class="cup" @click="handleEdit(row)">{{ row.title }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="author"
        label="作者"
        width="100"
        show-overflow-tooltip
      >
        <template slot-scope="{ row }">
          <span>{{ row.author || '--' }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="发布状态" width="100">
        <template slot-scope="{ row }">
          <span v-if="row.status == 0" class="color-info">未发布</span>
          <span v-if="row.status == 1" class="color-info">已发布</span>
        </template>
      </el-table-column>
      <el-table-column prop="title" label="审核状态" width="100">
        <template slot-scope="{ row }">
          <span v-if="row.auditStatus == 0" class="color-info">暂存</span>
          <span v-if="row.auditStatus == 1" class="color-info">待审核</span>
          <span v-if="row.auditStatus == 2" class="color-success">已通过</span>
          <span v-if="row.auditStatus == 3" class="color-danger">未通过</span>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="140">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button type="success" size="mini" @click="handlePreview(row)"
              >预览</el-button
            >
            <el-button type="primary" size="mini" @click="handleAudit(row)"
              >审核</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
  </div>
</template>
<script>
export default {
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        auditStatus: '1',
        journalId: '0',
      },
      tableData: [],
      pageObj: {},
    }
  },

  mounted() {
    this.getList()
    this.$bus.$on('refreshNewsContentsList', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    this.$bus.$off('refreshNewsContentsList')
  },
  watch: {
    classifyId: {
      handler() {
        this.getList()
        this.$refs.multipleTable.clearSelection()
      },
    },
  },
  methods: {
    async getList() {
      let res = await this.$store.dispatch('queryNewsContents', this.listQuery)
      this.tableData = res.data
      this.pageObj = res
    },
    //审核
    handleAudit(row) {
      this.$bus.$emit('articleAudit', [row])
    },
    //预览
    handlePreview(row) {
      this.$bus.$emit('collectLogPreview', row)
    },
    //批量操作
    handleSelectionChange(val) {
      this.$bus.$emit('changeSelectedData', val)
    },
  },
}
</script>